class MobilesController < ApplicationController
  
   layout "mobile"
   
   def home
      @title = 'Home'
   end
   
   
   
   def listcomputer
      @title = 'Liste des ordinateurs'
      @Computers = Machine.all
   end
   
   def detailcomputer
      @title = 'Informations de l\'ordinateur'
      @Computer = Machine.find(params[:id])
      @incidentsPie = Incident.find_by_sql(["select incident_type, count(*) As resultat from incidents where machine_id = ? group by incident_type", params[:id]])
      
   end
   
 

   def listroom
      @title = 'Liste des salles'
      @Rooms = Room.all
   end
   
   def detailroom
      @title = 'Liste des ordinateurs de la salle'
      @Machines = Machine.find(:all, :conditions => ["room_id = ?", params[:id]])
   end
   
   
   def listbreakdown
      @title = 'Liste des ordinateurs avec anomalies'
      @Breakdowns = Incident.find_by_sql("SELECT machine_id, count(*) AS resultat from incidents where resolution_date IS NULL group by machine_id")
   end
   
   def listIncidentByComputer
      @Machine = Machine.find(params[:id])
      @Breakdowns = Incident.find(:all, :conditions => ["resolution_date IS NULL AND machine_id = ?", params[:id]])
      
      @title = 'Liste des anomalies ' + @Machine.id.to_s
   end
   
end
